//
//  MListServiceViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/24.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "MListServiceViewController.h"
//#import "NTLYLawyer.h"

@interface MListServiceViewController ()

@end

@implementation MListServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArray=[NSMutableArray array];
    
    //    [[MListService sharedClient]getProductListWithKid:@"0" latitude:@"23.01867" longtitude:@"113.13816" radius:@"1000" sort:@"Price" typeId:self.typeId priceId:self.priceId sizeId:self.sizeId pageIndex:[NSString stringWithFormat:@"%d",1] completion:^(NSMutableArray *result){
    //        if(result.count==0){
    //            NSLog(@"无数据");
    //        }else{
    //            NSLog(@"有数据");
    //        }
    //    } failure:^(NSString *error){
    //        NSLog(@"失败啦");
    //    }];
    
    NSString *url=@"http://www.huobi3j.com/product/searchproduct?typeid=&sizeid=&radius=1000&priceid=&pageindex=1&sort=Price&lng=113.13816&kid=0&lat=23.01867&";
    //NSString *url=@"http://www.huobi3j.com/api/HotKeyword";
    
    
    [NSURLConnection sendAsynchronousRequest:[self apiPOSTRequest:url] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        
        if (error) {
            
        }else{
            NSDictionary *dis=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
            NSLog(@"NSDictionary is %@",dis);
            NSArray *array=[dis objectForKey:@"contents"];
            //            for (NSDictionary *dct in array) {
            //                model=[[MListModel1 alloc]init];
            //                model=[MListModel1 modelObjectWithDictionary:dct];
            //                NSLog(@"model is %@",model.KName);
            //            }
            
            MListHttpResult *newModel=[[MListHttpResult alloc]init];
            self.dataArray=[newModel  getListResultWithArrayJSON:array];
            
        }
        if (self.dataArray.count!=0) {
             [mytableView reloadData];
        }
        //        NSArray *array=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
        //        NSLog(@"--------%@",array);
        //        NSLog(@"data");
    }];

    
    // Do any additional setup after loading the view from its nib.
}
-(NSMutableURLRequest *)apiPOSTRequest:(NSString *)urlString{
    NSURL *url=[NSURL URLWithString:urlString];
    
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url cachePolicy:0  timeoutInterval:200];
    
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    [request setHTTPMethod:@"POST"];
    
    return request;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
        return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    static NSString *cellStr = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    
    MListModel *newlistModel=[self.dataArray objectAtIndex:indexPath.row];
        NSString *menu =newlistModel.companyName;
        cell.textLabel.text = menu;
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
//-(NSString *)getKIDwithKeyword:(NSString *)keyword completion:(g)

@end
